import React from "react";
class App extends React.PureComponent {
  state = {
    show: true,
    originArr: ["hello", "nihao", "veryGOODS"],
  };

  changeShow = () => {
    this.setState({
      show: !this.state.show,
    });
  };
  getArr() {
    let newArr = [];
    this.state.originArr.forEach((item) => {
      newArr.push(<div key={item}>{item}</div>);
    });
    console.log(newArr);
    return newArr;
  }
  addData = () => {
    let _arr = [...this.state.originArr];
    _arr.push("hello");
    this.setState({
      originArr: _arr,
    });
  };
  render() {
    return (
      <div className="App">
        <div>条件渲染</div>
        <div>{this.state.show && <div>显示</div>}</div>
        <button onClick={this.changeShow}>改变show状态</button>
        <div>分割线</div>
        <div>列表渲染</div>
        <div>{this.getArr()}</div>
        <div>{this.state.originArr}</div>
        <button onClick={this.addData}>添加数据</button>
      </div>
    );
  }
}

export default App;
